package com.rocket.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rocket.R;
import com.rocket.database.Missile83Sql;
import com.rocket.database.MissileJD89Sql;
import com.rocket.database.RocketBL1Sql;
import com.rocket.database.RocketHJD82Sql;
import com.rocket.database.RocketRYI6300Sql;
import com.rocket.database.RocketWR98Sql;
import com.rocket.entity.FirearmType;
import com.rocket.entity.Missile83;
import com.rocket.entity.MissileJD89;
import com.rocket.entity.RocketBL1;
import com.rocket.entity.RocketHJD82;
import com.rocket.entity.RocketRYI6300;
import com.rocket.entity.RocketWR98;
import com.rocket.entity.Work;
import com.rocket.excel.Missile83ExcelUtil;
import com.rocket.excel.MissileJD89ExcelUtil;
import com.rocket.excel.RocketBL1ExcelUtil;
import com.rocket.excel.RocketHJD82ExcelUtil;
import com.rocket.excel.RocketRYI6300ExcelUtil;
import com.rocket.excel.RocketWR98ExcelUtil;
import com.rocket.util.DialogUtil;
import com.rocket.util.FileUtils;
import com.rocket.util.MenuUtil;
import com.rocket.util.ParabolaUtil;
import com.rocket.util.ParabolaUtil.DrawPoint;

public class TubiaoActivity extends MenuActivity {

	Button			buttonBack;
	Button			buttonPrint;

	TextView		tvType;

	LinearLayout	tubiaoLayout;

	ParabolaUtil	mParabolaUtil;
	
	ImageView image;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tubiao);

		final Work work = (Work) getIntent().getSerializableExtra("work");

		buttonBack = (Button) findViewById(R.id.buttonback);
		buttonBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		buttonPrint = (Button) findViewById(R.id.buttonprint);
		buttonPrint.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (work.firearmType) {
					case FirearmType.MISSILE_83: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/missile83_" + System.currentTimeMillis() + ".xls";
						Missile83ExcelUtil.getInstance().export(path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
					case FirearmType.MISSILE_JD89: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/missile_jd89_" + System.currentTimeMillis() + ".xls";
						MissileJD89ExcelUtil.getInstance().export(path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
					case FirearmType.ROCKET_BL1: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/rocket_bl1_" + System.currentTimeMillis() + ".xls";
						RocketBL1ExcelUtil.getInstance().export(RocketBL1Sql.getInstance().query(),path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
					case FirearmType.ROCKET_HJD82: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/rocket_hjd82_" + System.currentTimeMillis() + ".xls";
						RocketHJD82ExcelUtil.getInstance().export(RocketHJD82Sql.getInstance().query(),path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
					case FirearmType.ROCKET_RY6300: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/rocket_ryi6300_" + System.currentTimeMillis() + ".xls";
						RocketRYI6300ExcelUtil.getInstance().export(RocketRYI6300Sql.getInstance().query(),path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
					case FirearmType.ROCKET_WR98: {
						String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/rocket_wr98_" + System.currentTimeMillis() + ".xls";
						RocketWR98ExcelUtil.getInstance().export(RocketWR98Sql.getInstance().query(),path);
						showToast("Excel文件保存成功，文件路径为："+path);
						break;
					}
				}
				String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Rocket/parabola_" + System.currentTimeMillis() + ".png";
				
//				image.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//				image.layout(0, 0, 800, 480);
				image.buildDrawingCache(true);
				Bitmap bitmap = image.getDrawingCache(true);
				FileUtils.saveImage(bitmap, path);

			}
		});

		tvType = (TextView) findViewById(R.id.title);

		tubiaoLayout = (LinearLayout) findViewById(R.id.layouttubiao);
		mParabolaUtil = new ParabolaUtil(TubiaoActivity.this);
		switch (work.firearmType) {
			case FirearmType.MISSILE_83: {
				tvType.setText("83型炮弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.missile83_item_title, null);
				tubiaoLayout.addView(title);
				int[] angles = new int[] { 85, 80, 75, 70, 65, 60, 55, 50, 45 };
				for (int j = 0; j < angles.length; j++) {
					ArrayList<Missile83> missiles = Missile83Sql.getInstance().queryWithAngle(angles[j]);

					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.missile83_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(angles[j] + "°");
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					TextView tv8 = (TextView) line.findViewById(R.id.tv8);
					TextView[] lines = new TextView[] { tv2, tv3, tv4, tv5, tv6, tv7, tv8 };

					for (int i = 0; i < missiles.size(); i++) {
						Missile83 missile = missiles.get(i);
						TextView tv = lines[i];
						tv.setText(String.valueOf(missile.height + "/" + missile.length));
						if (work.misseleTime == missile.time && work.missileAngle == missile.angel) {
							tv.setTextColor(Color.RED);
							tv1.setTextColor(Color.RED);
//							mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, missile.topLength / 10f, missile.topHeight / 10, missile.range / 10, 0);
							ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
							drawPoints.add(new DrawPoint(missile.length / 20, missile.height / 20));
							mParabolaUtil.drawParobola(0, 0,  missile.topLength / 20f, missile.topHeight / 20, missile.range / 20, 0, drawPoints);
						}
					}

					tv1.setBackgroundResource(R.drawable.black0);
					if (j % 2 == 0) {// 偶数行
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
						tv8.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
						tv8.setBackgroundResource(R.drawable.black1);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			case FirearmType.MISSILE_JD89: {
				tvType.setText("JD-89型炮弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.missilejd89_item_title, null);
				tubiaoLayout.addView(title);
				int[] angles = new int[] { 85, 80, 75, 70, 65, 60, 55, 50, 45 };
				for (int j = 0; j < angles.length; j++) {
					ArrayList<MissileJD89> missiles = MissileJD89Sql.getInstance().queryWithAngle(angles[j]);

					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.missilejd89_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(angles[j] + "°");
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					TextView[] lines = new TextView[] { tv2, tv3, tv4, tv5, tv6, tv7 };

					for (int i = 0; i < missiles.size(); i++) {
						MissileJD89 missile = missiles.get(i);
						TextView tv = lines[i];
						tv.setText(String.valueOf(missile.height + "/" + missile.length));
						if (work.misseleTime == missile.time && work.missileAngle == missile.angel) {
							tv.setTextColor(Color.RED);
							tv1.setTextColor(Color.RED);
							ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
							drawPoints.add(new DrawPoint(missile.length / 20, missile.height / 20));
							mParabolaUtil.drawParobola(0, 0,  missile.topLength / 20f, missile.topHeight / 20, missile.range / 20, 0, drawPoints);
						}
					}

//					int size = missiles.size();
//					mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, missiles.get(size / 2).length / 10f, missiles.get(size / 2).height / 10, missiles.get(size - 1).length / 10f, missiles.get(size - 1).height / 10);

					tv1.setBackgroundResource(R.drawable.black0);
					if (j % 2 == 0) {// 偶数行
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			case FirearmType.ROCKET_BL1: {
				tvType.setText("BL-1型火箭弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.rocketbl1_item_title, null);
				tubiaoLayout.addView(title);

				ArrayList<RocketBL1> rockets = RocketBL1Sql.getInstance().query();
				for (int i = 0; i < rockets.size(); i++) {
					RocketBL1 rocket = rockets.get(i);
					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.rocketbl1_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(String.valueOf(rocket.angle));
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					tv2.setText(String.valueOf(rocket.startHeight));
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					tv3.setText(String.valueOf(rocket.startLength));
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					tv4.setText(String.valueOf(rocket.endHeight));
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					tv5.setText(String.valueOf(rocket.endLength));
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					tv6.setText(String.valueOf(rocket.destoryHeight));
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					tv7.setText(String.valueOf(rocket.destoryLength));
					TextView tv8 = (TextView) line.findViewById(R.id.tv8);
					tv8.setText(String.valueOf(rocket.topHeight));
					TextView tv9 = (TextView) line.findViewById(R.id.tv9);
					tv9.setText(String.valueOf(rocket.topLength));

					if (i % 2 == 0) {// 偶数行
						tv1.setBackgroundResource(R.drawable.black2);
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
						tv8.setBackgroundResource(R.drawable.black2);
						tv9.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv1.setBackgroundResource(R.drawable.black1);
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
						tv8.setBackgroundResource(R.drawable.black1);
						tv9.setBackgroundResource(R.drawable.black1);
					}
					if (work.rocketAngle == rocket.angle) {
						tv1.setTextColor(Color.RED);
						tv2.setTextColor(Color.RED);
						tv3.setTextColor(Color.RED);
						tv4.setTextColor(Color.RED);
						tv5.setTextColor(Color.RED);
						tv6.setTextColor(Color.RED);
						tv7.setTextColor(Color.RED);
						tv8.setTextColor(Color.RED);
						tv9.setTextColor(Color.RED);
//						mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, rocket.topLength / 10f, rocket.topHeight / 10f, rocket.length / 10f, 0);
						ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
						drawPoints.add(new DrawPoint(rocket.startLength / 20, rocket.startHeight / 20));
						drawPoints.add(new DrawPoint(rocket.topLength / 20, rocket.topHeight / 20));
						drawPoints.add(new DrawPoint(rocket.endLength / 20, rocket.endHeight / 20));
						drawPoints.add(new DrawPoint(rocket.destoryLength / 20, rocket.destoryHeight / 20));
						mParabolaUtil.drawParobola(0, 0, rocket.topLength / 20f, rocket.topHeight / 20f, rocket.length / 20f, 0, drawPoints);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			case FirearmType.ROCKET_HJD82: {
				tvType.setText("HJD-82型火箭弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.rockethjd82_item_title, null);
				tubiaoLayout.addView(title);

				ArrayList<RocketHJD82> rockets = RocketHJD82Sql.getInstance().query();
				for (int i = 0; i < rockets.size(); i++) {
					RocketHJD82 rocket = rockets.get(i);
					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.rockethjd82_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(String.valueOf(rocket.angle));
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					tv2.setText(String.valueOf(rocket.startHeight));
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					tv3.setText(String.valueOf(rocket.startLength));
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					tv4.setText(String.valueOf(rocket.endHeight));
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					tv5.setText(String.valueOf(rocket.endLength));
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					tv6.setText(String.valueOf(rocket.topHeight));
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					tv7.setText(String.valueOf(rocket.topLength));

					if (i % 2 == 0) {// 偶数行
						tv1.setBackgroundResource(R.drawable.black2);
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv1.setBackgroundResource(R.drawable.black1);
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
					}
					if (work.rocketAngle == rocket.angle) {
						tv1.setTextColor(Color.RED);
						tv2.setTextColor(Color.RED);
						tv3.setTextColor(Color.RED);
						tv4.setTextColor(Color.RED);
						tv5.setTextColor(Color.RED);
						tv6.setTextColor(Color.RED);
						tv7.setTextColor(Color.RED);
//						mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, rocket.topLength / 10f, rocket.topHeight / 10f, rocket.length / 10f, 0);
						ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
						drawPoints.add(new DrawPoint(rocket.startLength / 20, rocket.startHeight / 20));
						drawPoints.add(new DrawPoint(rocket.topLength / 20, rocket.topHeight / 20));
						drawPoints.add(new DrawPoint(rocket.endLength / 20, rocket.endHeight / 20));
						mParabolaUtil.drawParobola(0, 0, rocket.topLength / 20f, rocket.topHeight / 20f, rocket.length / 20f, 0, drawPoints);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			case FirearmType.ROCKET_RY6300: {
				tvType.setText("RYI-6300型火箭弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.rocketryi6300_item_title, null);
				tubiaoLayout.addView(title);

				ArrayList<RocketRYI6300> rockets = RocketRYI6300Sql.getInstance().query();
				for (int i = 0; i < rockets.size(); i++) {
					RocketRYI6300 rocket = rockets.get(i);
					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.rocketryi6300_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(String.valueOf(rocket.angle));
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					tv2.setText(String.valueOf(rocket.startHeight));
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					tv3.setText(String.valueOf(rocket.startLength));
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					tv4.setText(String.valueOf(rocket.topHeight));
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					tv5.setText(String.valueOf(rocket.topLength));
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					tv6.setText(String.valueOf(rocket.endHeight));
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					tv7.setText(String.valueOf(rocket.endLength));
					TextView tv8 = (TextView) line.findViewById(R.id.tv8);
					tv8.setText(String.valueOf(rocket.length));

					if (i % 2 == 0) {// 偶数行
						tv1.setBackgroundResource(R.drawable.black2);
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
						tv8.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv1.setBackgroundResource(R.drawable.black1);
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
						tv8.setBackgroundResource(R.drawable.black1);
					}
					if (work.rocketAngle == rocket.angle) {
						tv1.setTextColor(Color.RED);
						tv2.setTextColor(Color.RED);
						tv3.setTextColor(Color.RED);
						tv4.setTextColor(Color.RED);
						tv5.setTextColor(Color.RED);
						tv6.setTextColor(Color.RED);
						tv7.setTextColor(Color.RED);
						tv8.setTextColor(Color.RED);
//						mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, rocket.topLength / 10f, rocket.topHeight / 10f, rocket.length / 10f, 0);
						ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
						drawPoints.add(new DrawPoint(rocket.startLength / 20, rocket.startHeight / 20));
						drawPoints.add(new DrawPoint(rocket.topLength / 20, rocket.topHeight / 20));
						drawPoints.add(new DrawPoint(rocket.endLength / 20, rocket.endHeight / 20));
						mParabolaUtil.drawParobola( 0, 0, rocket.topLength / 20f, rocket.topHeight / 20f, rocket.length / 20f, 0, drawPoints);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			case FirearmType.ROCKET_WR98: {
				tvType.setText("WR-98型火箭弹");
				LinearLayout title = (LinearLayout) getLayoutInflater().inflate(R.layout.rockethjd82_item_title, null);
				tubiaoLayout.addView(title);

				ArrayList<RocketWR98> rockets = RocketWR98Sql.getInstance().query();
				for (int i = 0; i < rockets.size(); i++) {
					RocketWR98 rocket = rockets.get(i);
					LinearLayout line = (LinearLayout) getLayoutInflater().inflate(R.layout.rockethjd82_item, null);
					TextView tv1 = (TextView) line.findViewById(R.id.tv1);
					tv1.setText(String.valueOf(rocket.angle));
					TextView tv2 = (TextView) line.findViewById(R.id.tv2);
					tv2.setText(String.valueOf(rocket.startHeight));
					TextView tv3 = (TextView) line.findViewById(R.id.tv3);
					tv3.setText(String.valueOf(rocket.startLength));
					TextView tv4 = (TextView) line.findViewById(R.id.tv4);
					tv4.setText(String.valueOf(rocket.endHeight));
					TextView tv5 = (TextView) line.findViewById(R.id.tv5);
					tv5.setText(String.valueOf(rocket.endLength));
					TextView tv6 = (TextView) line.findViewById(R.id.tv6);
					tv6.setText(String.valueOf(rocket.topHeight));
					TextView tv7 = (TextView) line.findViewById(R.id.tv7);
					tv7.setText(String.valueOf(rocket.topLength));

					if (i % 2 == 0) {// 偶数行
						tv1.setBackgroundResource(R.drawable.black2);
						tv2.setBackgroundResource(R.drawable.black2);
						tv3.setBackgroundResource(R.drawable.black2);
						tv4.setBackgroundResource(R.drawable.black2);
						tv5.setBackgroundResource(R.drawable.black2);
						tv6.setBackgroundResource(R.drawable.black2);
						tv7.setBackgroundResource(R.drawable.black2);
					} else {// 奇数行
						tv1.setBackgroundResource(R.drawable.black1);
						tv2.setBackgroundResource(R.drawable.black1);
						tv3.setBackgroundResource(R.drawable.black1);
						tv4.setBackgroundResource(R.drawable.black1);
						tv5.setBackgroundResource(R.drawable.black1);
						tv6.setBackgroundResource(R.drawable.black1);
						tv7.setBackgroundResource(R.drawable.black1);
					}
					if (work.rocketAngle == rocket.angle) {
						tv1.setTextColor(Color.RED);
						tv2.setTextColor(Color.RED);
						tv3.setTextColor(Color.RED);
						tv4.setTextColor(Color.RED);
						tv5.setTextColor(Color.RED);
						tv6.setTextColor(Color.RED);
						tv7.setTextColor(Color.RED);
//						mParabolaUtil = new ParabolaUtil(TubiaoActivity.this, 0, 0, rocket.topLength / 10f, rocket.topHeight / 10f, rocket.length / 10f, 0);
						ArrayList<DrawPoint> drawPoints = new ArrayList<DrawPoint>();
						drawPoints.add(new DrawPoint(rocket.startLength / 20, rocket.startHeight / 20));
						drawPoints.add(new DrawPoint(rocket.topLength / 20, rocket.topHeight / 20));
						drawPoints.add(new DrawPoint(rocket.endLength / 20, rocket.endHeight / 20));
						mParabolaUtil.drawParobola(0, 0, rocket.topLength / 20f, rocket.topHeight / 20f, rocket.length / 20f, 0, drawPoints);
					}
					tubiaoLayout.addView(line);
				}
				break;
			}
			default:
				break;
		}

		image = (ImageView)findViewById(R.id.parabola);
		image.setDrawingCacheEnabled(true);
		if(mParabolaUtil != null){
			image.setImageBitmap(mParabolaUtil.getmDrawBitmap());
		}

	}

	@Override
	protected void openMenu() {
		String[] texts = new String[] { "火器选择", "添加站点", "历史查询", "退出程序" };
		Integer[] images = new Integer[] { R.drawable.menu_logout, R.drawable.menu_sys_add_buddy,
				R.drawable.menu_sys_search_buddy, R.drawable.menu_icon };
		mMenu = new MenuUtil(TubiaoActivity.this, getLayoutInflater().inflate(
				R.layout.tubiao, null), texts, images);
		mMenu.setMenuItemSelectedLinstener(new OnClickListener() {

			public void onClick(View v) {
				int tag = (Integer) v.getTag();
				switch (tag) {
					case 0:
					mMenu.dismiss();
					Intent intent1 = new Intent(TubiaoActivity.this, ChoseFirearmActivity.class);
					intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent1);
					break;
				case 1:
					mMenu.dismiss();
					Intent intent2 = new Intent(TubiaoActivity.this, WorkStationAddActivity.class);
					intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent2);
					break;
				case 2:
					mMenu.dismiss();
					Intent intent3 = new Intent(TubiaoActivity.this, HistoryQueryActivity.class);
					intent3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent3);
					break;
				case 3:
					mMenu.dismiss();
					mDialog = new DialogUtil(TubiaoActivity.this);
					mDialog.setTitle("退出确认");
					mDialog.setMessage("确定退出吗？");
					mDialog.setPositiveButton("确定", new OnClickListener() {

						public void onClick(View v) {
							mDialog.dismiss();
							Intent intent = new Intent(TubiaoActivity.this, MainActivity.class);
							intent.putExtra("Flag", 1);
							intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
							startActivity(intent);
						}
					});
					mDialog.setNegativeButton("取消", null);
					mDialog.show();
					break;
				default:
					break;
			}
		}
		});
		mMenu.show();
	}
}
